package top.glkj.hms.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import top.glkj.hms.utils.Status;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

/**
 * 订单表
 *
 * @author : xgl
 * @version : 0.0.1
 * @date :2020/11/1 0:41
 */
@EqualsAndHashCode(callSuper = true)
@Entity
@Table(name = "hms_order_from")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class OrderForm extends BaseEntity {
    /**
     * 订单编号
     */
    @Column(name = "order_number")
    private String orderNumber;
    /**
     * 订单创建用户
     */
    @Column(name = "insert_user_id")
    private Long insertUser;
    /**
     * 订单房间
     */
    @Fetch(FetchMode.SUBSELECT)
    @ManyToMany(targetEntity = Room.class,cascade = CascadeType.REFRESH)
    @JoinTable(name = "hms_order_form_rooms",
            //当前对象在中间表中的外键
            joinColumns = {@JoinColumn(name = "order_form_id", referencedColumnName = "id")},
            //对方对象在中间表中的外键
            inverseJoinColumns = {@JoinColumn(name = "room_id", referencedColumnName = "id")}
    )
    private List<Room> roomList;
    /**
     * 支付方式，
     */
    @Column(name = "payment_method")
    private String paymentMethod;

    /**
     * 开始时间
     */
    @Column(name = "start_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date startTime;
    /**
     * 结束时间
     */
    @Column(name = "end_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date endTime;

    /**
     * 订单状态 创建，支付，入住，加时，补费，结费，结束
     */
    private Status status;

    /**
     * 订单详情内容
     */
    @Fetch(FetchMode.SUBSELECT)
    @ManyToMany(targetEntity = HotelFacilities.class,cascade = CascadeType.REFRESH)
    @JoinTable(name = "hms_hotel_facilities_order_forms",
            //当前对象在中间表中的外键
            joinColumns = {@JoinColumn(name = "order_form_id", referencedColumnName = "id")},
            //对方对象在中间表中的外键
            inverseJoinColumns = {@JoinColumn(name = "hotel_facilities_id", referencedColumnName = "id")}
    )
    private List<HotelFacilities> hotelFacilitiesList;

    /**
     * 预付款
     */
    @Column(name = "prepare_money")
    private double prepareMoney= 0;

    /**
     * 实际费用
     */
    @Column(name = "total_money")
    private double totalMoney= 0;

    /**
     * 折后费用
     */
    @Column(name = "discounted_money")
    private double discountedMoney = 0;
    /**
     * 实际待支付费用
     */
    @Column(name = "give_money")
    private double giveMoney= 0;
    /**
     *  id构造方法
     * @param id
     */
    public OrderForm(Long id) {
        super(id);
    }
}
